package dr.incomeapp.view.miniView;

import java.text.DecimalFormat;
import java.util.Calendar;

import android.content.Context;
import android.view.LayoutInflater;
import android.widget.TextView;
import dr.incomeapp.R;
import dr.incomeapp.bean.IncomeBean;
import dr.incomeapp.view.MyView;

public class IncomeMiniView extends MyView {

	public IncomeMiniView(Context c, IncomeBean incomeBean) {
		super(c);
		LayoutInflater mInflater = (LayoutInflater) c
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		mInflater.inflate(R.layout.income_mini_view, this, true);
		setIncomeBean(incomeBean);
	}

	public void setIncomeBean(IncomeBean incomeBean) {
		TextView tvTitle = (TextView) this.findViewById(R.id.tvTitle);
		tvTitle.setText(incomeBean.getName());
		
		
		
		Calendar cal = Calendar.getInstance();
	    cal.setTime(incomeBean.getStartDate());
	    int day = cal.get(Calendar.DAY_OF_MONTH);
	    String strDay = "0";
	    if(day > 9){
	    	strDay = String.valueOf(day);
	    }else{
	    	strDay += String.valueOf(day);
	    }
		
		TextView tvDate = (TextView) this.findViewById(R.id.tvDate);
		tvDate.setText(strDay);
		
		
		DecimalFormat df = new DecimalFormat();
		df.setMinimumFractionDigits(2);
		df.setMaximumFractionDigits(2);

		TextView tvValue = (TextView) this.findViewById(R.id.tvValue);
		tvValue.setText(df.format(incomeBean.getMoney()));
		

		

		
		
		
		 if(incomeBean.isCost()){
			 tvValue.setTextColor(getResources().getColor(R.color.colorred));

		 }else{
			 tvValue.setTextColor(getResources().getColor(R.color.colorgreen));

		 }

	}
}
